<?php

header("Content-Type: text/html;charset=utf8");

class SchoolDb {

    private $mysql;

    public function __construct(InMysql $mysql = null) {
        if ($mysql == null) {
            $this->mysql = new InMysql();
        } else {
            $this->mysql = $mysql;
        }
    }

    public function getSchoolList() {
        $sql = "select * from school where is_show = 1 order by scid desc ";
        return $this->mysql->fetchData($sql);
    }

    public function getZoneList() {
        $sql = "select * from zone where is_show = 1;";
        return $this->mysql->fetchData($sql);
    }
    public function deleteZone($id){

        $sql = "delete from zone where zid = '$id'";
        return $this->mysql->executeData($sql);

    }
    public function deleteSchool($id){
        $sql = "delete from school where scid = " . $id;
        return $this->mysql->executeData($sql);
    }
    public function querySchool($name){
        $sql = "select * from school where sname='$name'";
        return $this->mysql->fetchData($sql);

    }
    public function queryRegion($name){
        $sql = "select * from zone where name='$name'";
        return $this->mysql->fetchData($sql);

    }
    public function addSchool($id,$name,$time){

        $sql="insert into school(sname,zone,ctime)values ('$name','$id','$time')";
        return $this->mysql->insertData($sql);
    }
    public function editSchool($id,$name){
        $sql="update school set sname='$name' where scid='$id'";
        return $this->mysql->executeData($sql);
    }
    public function addRegion($name,$type,$remark,$pzone,$time){
        $sql="insert into zone(name,type,remark,pzone,addtime)values ('$name','$type','$remark','$pzone','$time')";
        return $this->mysql->insertData($sql);

    }
    public function queryZone($id){
        $sql = "select * from zone where pzone='$id'";
        return $this->mysql->fetchData($sql);

    }
    public function querySchoolZone($id){

        $sql = "select * from school where zone='$id'";
        return $this->mysql->fetchData($sql);
    }

}
